﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web.Security;
using LOGICSMS.Models;

namespace LOGICSMS.Controllers
{
    
    public class LoginController : ApiController
    {
        [Route("Presentation/user/login")]
        [HttpPost]
        public string login(user u)
        {
            //bool result = false;
            string username = u.UserId;
            string password = u.password;
            string clerk = "clerk";
            string norole = "norole";
            string employee = "employee";
            if (Membership.ValidateUser(username, password))
            {
                stationerystoreEntities se = new stationerystoreEntities();
                string role;
                //string[] roles;

                //roles=Roles.GetRolesForUser();

                
                user user = new user();
                user = se.users.Find(username);
                role = user.role.RoleName;
                if (role==employee)
                    return employee;
                else if (role==clerk)
                    return clerk;
                else
                    return norole;
                

            }
            else
                return norole;

 
        }
     
    }
}
